package com.example.demo.config;

import javax.activation.DataSource;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.druid.pool.DruidDataSource;

import lombok.extern.log4j.Log4j2; 

@Log4j2
@Configuration
//扫描 Mapper 接口并容器管理
//@MapperScan(basePackages=DataSourceConfig.PACKAGE,sqlSessionFactoryRef="sqlserverSqlSessionFactory")
@MapperScan("com.example.demo.mapper") //扫描的是Mapper.xml 中 namespace 指向值的包位置
public class DataSourceConfig {
	
	//精确到 sqlserver 目录，以便跟其他数据源隔离 
    static final String ALIASES_PACKAGE = "com.example.demo.entity";
	static final String MAPPER_LOCATION = "classpath:mappers/*Mapper.xml";	
	
	@Value("${spring.datasource.druid.password}")
	private String password;
	
	@Bean
	@ConfigurationProperties("spring.datasource.druid")
	public DruidDataSource druidDataSource() {
		DruidDataSource dataSource=new DruidDataSource();	 
		log.info("获取数据库连接密码:"+password);		
		dataSource.setPassword(password);
		return dataSource;
	}
	 
}
	 

 
